<?php 
    //清除图片session
    $this->session->unset_userdata('file_info');
    $this->session->unset_userdata('fileid');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $this->config->item('charset');?>">
        <title>编辑产品</title>
        <style type="text/css">
            <!--
            body { background-image: url(<?php echo base_url();?>public/images/allbg.gif); }
            .multipic {
                border: 1px dashed #FC6;
            }
            .albCt {
                border-bottom: 1px dashed #FC0;
                margin-bottom: 10px;
                padding-bottom:10px;
            }
            .albCt img{
                cursor:pointer;
            }
            -->
        </style>
        <link href="<?php echo base_url();?>public/css/base.css" rel="stylesheet" type="text/css">
        <link href='<?php echo base_url();?>public/css/tb-box.css' rel='stylesheet' type='text/css' />
        <link href="<?php echo base_url();?>public/css/swfupload.css" rel="stylesheet" type="text/css" /> 
        <script type="text/javascript" src="<?php echo base_url();?>public/js/dedeajax2.js"></script>
        <script type="text/javascript" src="<?php echo base_url();?>public/js/main.js"></script>
        <script type="text/javascript" src="<?php echo base_url();?>public/js/album.js"></script>
        <script type="text/javascript" src="<?php echo base_url();?>public/js/handlers.js"></script>
        <script type="text/javascript" src="<?php echo base_url();?>public/js/swfupload/swfupload.js"></script>
        <script language="javascript">
            var swfu = null;
            var vcc = 0;
            window.onload = function ()
            {
                swfu = new SWFUpload(
                    {
                        // Backend Settings
                        upload_url: "<?php echo site_url("admin/product/img_add"); ?>",
                        post_params: {"PHPSESSID": "5a52vlcnclagu3ijpg7o7l2pc7", "dopost" : ""},

                        // File Upload Settings
                        file_size_limit : "2 MB",    // 2MB
                        file_types : "*.jpg; *.gif; *.png",
                        file_types_description : "选择 JPEG/GIF/PNG 格式图片",
                        file_upload_limit : "0",

                        file_queue_error_handler : fileQueueError,
                        file_dialog_complete_handler : fileDialogComplete,
                        upload_progress_handler : uploadProgress,
                        upload_error_handler : uploadError,
                        upload_success_handler : uploadSuccess,
                        upload_complete_handler : uploadComplete,

                        button_image_url : "<?php echo base_url();?>public/images/SmallSpyGlassWithTransperancy_17x18.png",
                        button_placeholder_id : "spanButtonPlaceholder",
                        button_width: 250,
                        button_height: 18,
                        button_text : '<span class="button">选择本地图片 <span class="buttonSmall">(单图最大为 2 MB，支持多选)</span></span>',
                        button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
                        button_text_top_padding: 0,
                        button_text_left_padding: 18,
                        button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                        button_cursor: SWFUpload.CURSOR.HAND,

                        // Flash Settings
                        flash_url : "<?php echo base_url();?>public/js/swfupload/swfupload.swf",

                        custom_settings : {
                            upload_target : "divFileProgressContainer"
                        },

                        // Debug Settings
                        debug: false
                });
            };
        </script> 



        <script lang='javascript' src='<?php echo base_url();?>public/js/kindeditor-4.1.2/kindeditor.js'></script>
        <script lang='javascript' src='<?php echo base_url();?>public/js/kindeditor-4.1.2/lang/zh_CN.js'></script>
        <script language="javascript">
            <!--
            var swfu = null;
            var arctype = 'article';
            function checkSubmit()
            {
                if(document.form1.title.value=='')
                    {
                    alert('名称不能为空！');
                    return false;
                }
                if(document.form1.typeid.value==0)
                    {
                    alert('请选择分类！');
                    return false;
                }
            }

            var editor;
            KindEditor.ready(function(K) {
                    editor = K.create('#content');
            });



            KindEditor.ready(function(K) {
                    var editor = K.editor({
                            allowFileManager : true
                    });
                    K('#image1').click(function() {
                            editor.loadPlugin('image', function() {
                                    editor.plugin.imageDialog({
                                            imageUrl : K('#url1').val(),
                                            clickFn : function(url, title, width, height, border, align) {
                                                K('#url1').val(url);
                                                editor.hideDialog();
                                            }
                                    });
                            });
                    });
            });




            -->
        </script>
    </head>
    <body topmargin="8">
        <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="60%" height="30"><IMG height=14 src="<?php echo base_url();?>public/images/book1.gif" width=20>&nbsp;<a href=""><u>产品列表</u></a> &gt;&gt; 发布产品</td>
                <td width="30%" align='right'>&nbsp; <a href="<?php echo site_url("admin/sort")?>">[<u>分类管理</u>]</a> </td>
            </tr>
        </table>





        <form name="form1" enctype="multipart/form-data" action="<?php echo site_url("admin/product/save"); ?>" method="post" onSubmit="return checkSubmit()">
            <input type="hidden" name="id" value="<?php echo $model->id;?>" />
            <input type="hidden" name="dopost" value="modify" />
            <table width="98%"  border="0" align="center" cellpadding="2" cellspacing="2" id="needset" style="border:1px solid #cfcfcf;background:#ffffff;">
                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;产品名称：</td>
                                <td width='408'><input name="title" type="text" id="title" value="<?php echo $model->title;?>" style="width:388px" /></td>
                                <td width="90">&nbsp;</td>
                                <td>
                                    &nbsp;
                                </td>
                            </tr>
                        </table></td>
                </tr>
                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td  width="90">&nbsp;自定义属性：</td>
                                <td align="left">

                                    <?php

                                        foreach ($arcatt_all_list->result() as $arcatt)
                                        {
                                            if(preg_match("#".$arcatt->att."#", $model->flag))
                                                echo "<input class='np' type='checkbox' name='flags[]' id='flags{$arcatt->att}' value='{$arcatt->att}' checked='checked' />{$arcatt->attname}[{$arcatt->att}]";
                                            else
                                                echo "<input class='np' type='checkbox' name='flags[]' id='flags{$arcatt->att}' value='{$arcatt->att}' />{$arcatt->attname}[{$arcatt->att}]";

                                        }

                                    ?>


                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td width="400%" height="24" colspan="2" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;缩略图：</td>
                                <td width="408">  <input name="url1" type="text" id="url1" style="width:260px" value="<?php echo $model->litpic;?>" size="16"/><input type="button" id="image1" value="选择图片" /></td>
                                <td> <img src="<?php echo $model->litpic;?>" width="150" height="100" id="picview" name="picview">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;来源：</td>
                                <td width="240">
                                    <input name="source" type="text" id="source" style="width:160px" value="<?php echo $model->source;?>" size="16"/>
                                </td>
                                <td width="90">作　者：</td>
                                <td>
                                    <input name="writer" type="text" id="writer" style="width:120px" value="<?php echo $model->writer;?>"/>

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;产品分类：</td>
                                <td>
                                    <select name='typeid' id='typeid'>
                                        <option value='0'>请选择分类...</option>
                                        <?php
                                            if ($treelist->num_rows() > 0)
                                            {
                                                foreach ($treelist->result() as $row)
                                                {
                                                    $s_count=count(explode('-',$row->path));
                                                    $s_length='';
                                                    for($i=1;$i<$s_count;$i++)
                                                    {
                                                        $s_length=$s_length.'─';
                                                    }
                                                    $s_select='';
                                                    if($row->id==$model->typeid)
                                                    {
                                                        $s_select='selected=\'selected\'';
                                                    }
                                                    echo " <option value='".$row->id."' ".$s_select.">".$s_length.$row->name."</option>";
                                                }
                                            }
                                        ?>

                                    </select>
                                </td>
                            </tr>
                        </table></td>
                </tr>


                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;内容摘要：</td>
                                <td width="449"><textarea name="description" rows="5" id="description" style="width:80%;height:50px"><?php echo $model->description;?></textarea></td>
                                <td width="261">&nbsp;</td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;发布时间：</td>
                                <td width="240">
                                    <input name="sendtime" type="text" id="sendtime" style="width:160px" value="<?php echo date("Y-m-d H:i:s",$model->sendtime);?>" size="26"/>
                                </td>
                                <td width="90">参考价格：</td>
                                <td>
                                    <input name="price" type="text" id="price" style="width:120px" value="<?php echo $model->price;?>"/>

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;产品规格：</td>
                                <td width="240">
                                    <input name="norm" type="text" id="norm" style="width:160px" value="<?php echo $model->norm;?>" size="16"/>
                                </td>
                                <td width="90">产品品牌：</td>
                                <td>
                                    <input name="brand" type="text" id="brand" style="width:120px" value="<?php echo $model->brand;?>"/>

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>
                    <td height="24" colspan="5" class="bline">
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;货币单位：</td>
                                <td width="240">
                                    <input name="crunit" type="text" id="crunit" style="width:160px" value="<?php echo $model->crunit;?>" size="16"/>
                                </td>
                                <td width="90">产品单位：</td>
                                <td>
                                    <input name="prunit" type="text" id="prunit" style="width:120px" value="<?php echo $model->prunit;?>"/>

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>

                <tr>   
                    <td colspan="2"></td>
                </tr>

                <tr>
                    <td height="28" colspan="2" bgcolor="#F9FCEF" class="bline2">
                        <div style='float:left;line-height:28px;'>&nbsp;<strong>内容：</strong></div>
                    </td>
                </tr>


                <tr>
                    <td width="100%" id="arcBody" class="bline" >
                        <textarea name="content" rows="5" id="content" style="width:700px;height:300px;"><?php echo $model->arcids;?></textarea>
                    </td>
                    <td width="255" align="center" valign="top" bgcolor="#FFFFCC" id="mPic" style="display:none">
                    </td>
                </tr>

                <tr>
                    <td height="24" bgcolor="#F9FCEF" class="bline2">&nbsp;<b>原有图片：</b></td>
                </tr>
                <tr>
                    <td height="24" colspan="4" class="bline"><table width='100%'>
                            <tr>
                                <td><div id="thumbnailsEdit">

                                        <?php
                                            $img_file=explode('|',$model->bigpic);
                                            for($i=0;$i<count($img_file);$i++)
                                            {
                                                if(!empty($img_file[$i])&&$img_file[$i]!='')
                                                {
                                                    $img_id=$i+1;
                                                    $file_info=array();
                                                    $file_info=$this->session->userdata('file_info');
                                                    $fileid=$this->session->userdata('fileid');
                                                    $fileid=$img_id;
                                                    $file_info[$fileid]=$img_file[$i];
                                                    $this->session->set_userdata('fileid',$fileid);
                                                    $this->session->set_userdata('file_info',$file_info);

                                                ?>
                                                <div class='albCt albEdit' id="albold<?php echo $img_id;?>">
                                                    <input type='hidden' name='imgurl1' value='' />
                                                    <input type='hidden' name='imgddurl1' value='' />
                                                    <img src='<?php echo base_url("public/uploads/$img_file[$i]") ;?>' width='150' /><a href="javascript:delAlbPicOld('<?php echo "./public/uploads/$img_file[$i]";?>', <?php echo $img_id;?>)">[删除]</a>
                                                </div>
                                                <?php
                                                }
                                            }
                                        ?>
                                    </div></td>
                            </tr>
                        </table></td>
                </tr>



                <tr>
                    <td height="24" colspan="5" >
                        <table width="800" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="90">&nbsp;<strong>增加新图片：</strong></td>
                                <td>  

                                    <div style="display: inline; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;">
                                        <span id="spanButtonPlaceholder"></span>
                                    </div>
                                </td>
                            </tr>
                        </table></td>
                </tr>


                <tr id="handfield">
                    <td colspan="4" class="bline" style="background:url(<?php echo base_url();?>public/images/albviewbg.gif) #fff 0 20px no-repeat;">
                        <table width='100%' height='160' style="margin:0 0 20px 0">
                            <tr>
                                <td>
                                    <div id="divFileProgressContainer" style="height:75px;"></div>
                                    <div id="thumbnails"></div>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>



            </table>






            <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="#F9FCEF" style="border:1px solid #cfcfcf;border-top:none;">
                <tr height="35">
                    <td width="17%">&nbsp;</td>
                    <td width="83%"><input name="imageField" type="image" src="<?php echo base_url();?>public/images/button_save.gif" width="60" height="22" class="np" border="0"  style="cursor:pointer;"/>
                        <img src="<?php echo base_url();?>public/images/button_reset.gif" width="60" height="22" border="0" onClick="location.reload();" style="cursor:pointer; "/>
                    </td>
                </tr>
            </table>
        </form>
        <div id="__tmpbody" style="display:none"></div>
        <script language='javascript'>InitPage();</script>
    </body>
</html>